<?php


namespace App\Model\Fanmh;


use EasySwoole\ORM\DbManager;

class GoodModel extends \EasySwoole\ORM\AbstractModel
{
    protected $connectionName = 'default';
    protected $tableName = 'fanmh_goods';

    //查询商品信息
    public function getGoodsInfo($uuid)
    {
        return DbManager::getInstance()->invoke(function ($client) use ($uuid) {
            $m = self::invoke($client);
            $m->field(["good_id", "good_name", "good_price"])->where(["good_id" => $uuid])->all();

            echo $m->lastQuery()->getLastQuery() . PHP_EOL;
            return $m->lastQueryResult()->getResult();
        });

    }

    //插入商品数据
    public function insertGoodInfo($data)
    {
        return DbManager::getInstance()->invoke(function ($client) use ($data){
            $m = self::invoke($client);
            $m->data($data,false)->save();
            return $m->lastQueryResult()->getLastInsertId();
        });
    }

    //修改商品信息
    public function updateGoodInfo($goodName,$goodPrice)
    {
        return DbManager::getInstance()->invoke(function ($client) use ($goodName,$goodPrice){
            $m = self::invoke($client);
            $m->update(['good_price' => $goodPrice], ['good_name' => $goodName]);
            return $m->lastQueryResult()->getAffectedRows();
        });
    }

    //删除商品信息

}